package org.example.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.example.pojo.*;
import org.example.service.TalentsService;
import org.example.service.impl.TalentsServiceImpl;
import org.example.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

@Controller
@Api(tags = "talents测试")
@RequestMapping("/talents")
public class TalentsController {

    @Autowired
    TalentsService talentsService;

    @ResponseBody
    @GetMapping("/list")
    @ApiOperation("人才库列表")
    public ResponseData list(
            @ApiParam("当前页") int page,
            @ApiParam("每一页的数据") int limit,
            @ApiParam("模糊查询数据")   String like){
//        使用分页插件

        if ("undefined".equals(like)){
            like=null;
        }
        System.out.println(like);

        PageHelper.startPage(page,limit);
        List<TalentsListVO> talentsListVOS = talentsService.showListTalents(like);


        PageInfo<TalentsListVO> talentsPageInfo = new PageInfo<>(talentsListVOS);

        //以json传输
        ResponseData jsonData = ResponseData.allResponse(talentsListVOS,"登录成功",100,(int)talentsPageInfo.getTotal());

        return jsonData;
    }

    @ResponseBody
    @GetMapping("/listStatus")
    @ApiOperation("模糊状态列表")
    public ResponseData listStatus( @ApiParam("模糊状态 录用状态")String like){



        List<TalentsListLikeVO> talentsListVOS = talentsService.showListTalentsListStatus(like);

        PageInfo<TalentsListLikeVO> talentsPageInfo = new PageInfo<>(talentsListVOS);

        //以json传输
        ResponseData jsonData = ResponseData.allResponse(talentsListVOS,"模糊状态列表",100,(int)talentsPageInfo.getTotal());

        return jsonData;
    }

    @ResponseBody
    @GetMapping("/isLookTalents/{id}/{remark}/{status}")
    @ApiOperation("根据id修改是否录用状态")
    public ResponseData isLookTalents( @ApiParam("id") @PathVariable Integer id,@ApiParam("相关备注") @PathVariable String remark,@ApiParam("状态") @PathVariable String status){

        boolean isHire = talentsService.updateIsHire(id, remark, status);

        return isHire?ResponseData.getSccesss("录用状态修改成功",100):ResponseData.getSccesss("录用状态修改失败",101);
    }


    @ResponseBody
    @GetMapping("/talentsEmp/{id}")
    @ApiOperation("显示录用的数据")
    public ResponseData talentsEmp(@ApiParam("id") @PathVariable Integer id){

        TalentsListVO talentsListVO = talentsService.looktalentNamePhone(id);
        return ResponseData.allResponse(talentsListVO,"名字和电话",100,0);
    }

    @ResponseBody
    @PostMapping("/addEmployee")
    @ApiOperation("入职手续")
    public ResponseData addEmployee(@ApiParam("员工对象")@RequestBody Employee employee,@ApiParam("修改状态的id，改为入职状态") Integer id){

        Boolean aBoolean = talentsService.addEmployeeDep(employee);
        if (aBoolean){
            talentsService.isAddEntry(id);
        }
        return aBoolean?ResponseData.getSccesss("添加成功",100):ResponseData.getSccesss("添加成功失败",101);
    }


    @ResponseBody
    @GetMapping("/oneShowList/{id}")
    @ApiOperation("根据id   点击查询后所有数据人才库列表")
    public ResponseData oneShowList(@ApiParam("id") @PathVariable int id){
        Talents talents = talentsService.oneShowList(id);

        return talents!=null?ResponseData.allResponse(talents,"查询成功",100,0):ResponseData.getSccesss("查询失败",101);
    }



}
